import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/pages/NotFound.dart';
import 'package:flutter_enjoy_plus/pages/home/NoticeDetail.dart';
import 'package:flutter_enjoy_plus/pages/house/building_list.dart';
import 'package:flutter_enjoy_plus/pages/house/house_detail.dart';
import 'package:flutter_enjoy_plus/pages/house/house_form.dart';
import 'package:flutter_enjoy_plus/pages/house/house_list.dart';
import 'package:flutter_enjoy_plus/pages/house/location_list.dart';
import 'package:flutter_enjoy_plus/pages/house/room_list.dart';
import 'package:flutter_enjoy_plus/pages/login/LoginPage.dart';
import 'package:flutter_enjoy_plus/pages/profile/ProfilePage.dart';
import 'package:flutter_enjoy_plus/pages/tabBar_page.dart';
import 'package:flutter_enjoy_plus/utils/TokenManager.dart';

Route<dynamic> onGenerateRoute(settings) {
  var token = tokenManager.getToken();
  if (token == '') {
    return MaterialPageRoute(builder: (context) => const LoginPage());
  } else {
    if (settings.name == '/profile') {
      print(settings.arguments);
      return MaterialPageRoute(
          builder: (context) => ProfilePage(
                userInfo: settings.arguments as Map<String, dynamic>,
              ));
    } else if (settings.name == '/house') {
      return MaterialPageRoute(builder: (context) => HouseList());
    } else if (settings.name == '/add_house') {
      return MaterialPageRoute(builder: (context) => LocationList());
    } else if (settings.name == '/building_list') {
      return MaterialPageRoute(
          builder: (context) => BuildingList(
                point: (settings.arguments as Map<String, dynamic>)["point"]
                    as String,
              ));
    } else if (settings.name == '/room_list') {
      return MaterialPageRoute(
          builder: (context) => RoomList(
                point: (settings.arguments as Map<String, dynamic>)["point"]
                    as String,
                building: (settings.arguments as Map<String, dynamic>)["build"]
                    as String,
              ));
    } else if (settings.name == '/house_form') {
      return MaterialPageRoute(
          builder: (context) =>
              HouseForm(params: settings.arguments as Map<String, dynamic>));
    } else if (settings.name == '/house_detail') {
      return MaterialPageRoute(
          builder: (context) =>
              HouseDetail(id: (settings.arguments as Map)['id'] as String));
    }
  }
  return MaterialPageRoute(builder: (context) => const NotFound());
  ;
}

Map<String, Widget Function(BuildContext)> routes = {
  '/': (context) => const TabsPage(),
  "/notice_detail": (context) => const NoticeDetail(),
  "/login": (context) => const LoginPage(),
  //"/profile": (context) => const ProfilePage()
};
